home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TIMING.SWG / 0013_Setting Timing at 21Khz.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  3KB  |  68 lines

  1. {
  2. CEES BINKHORST
  3.  
  4. >  Has anyone ever succeeded in setting the timer rate at a higher frequency
  5. > than 21KHz in protected mode? I've tried every possible thing, and it
  6. Could you give details on that 21KHz? Sounds rather a high rate.
  7.  
  8. > don't know whether I have enough IOPL as to make CLI and STI to work, but
  9. Try the following:
  10. }
  11.  
  12. {dr. dobb's 80286/386 #185}
  13. Function SensitiveOK : Boolean; Assembler; {sensitive instructions are: }
  14.                                     {IN    read a port           }
  15.                                     {OUT   Write to a port       }
  16.                                     {INS   read a String from a port}
  17.                                     {OUTS  Write a String to a port}
  18.                                     {CLI   disable interrupts    }
  19.                                     {STI   enable interrupts     }
  20. Asm
  21.   push  ax
  22.   push  bx
  23.   pushf                             {put flags 'I/O privilege level' (IOPL)}
  24.   pop   ax                          { into ax }
  25.   and   ax, 3000h                   {00110000 00000000 - mask all but iopl}
  26.                                     {ax = 00??0000 00000000 now}
  27.   shr   ax, 12                      {ax -> 00000000 000000??}
  28.                                     {compile With 286 instructions enabled!!}
  29.   mov   iopl, al
  30.   mov   bx, cs                      {current privilege level (cpl) is in cs}
  31.   and   bx, 3                       {00000000 00000011 - mask all but cpl}
  32.   mov   cpl, bl
  33.   cmp   bx, ax                      {compare cpl and iopl}
  34.   ja    @not_sensitive              {jump  if cpl > iopl}
  35.   clc
  36.   mov   @result, True               {sensitive instructions ok}
  37.   jmp   @exit
  38.  @not_sensitive:
  39.   stc
  40.   mov   @result, False              {sensitive instructions not ok}
  41.  @exit:
  42.   pop   bx
  43.   pop   ax
  44. end;
  45.  
  46. Function PrivilegeOK: Boolean; Assembler; {privileged instructions are:}
  47.                                     {HLT   halt the processor    }
  48.                                     {LGDT  load the GDT register }
  49.                                     {LIDT  load the interrupt-descriptor-}
  50.                                     {      table register        }
  51.                                     {LLDT  load the LDT register  }
  52.                                     {CLTS  clear the task-switched flag}
  53.                                     {LMSW  load the MSW          }
  54.                                     {LTR   load the task register}
  55. Asm
  56.   push  ax
  57.   mov   ax, cs                    {cpl resides in cs}
  58.   and   ax, 3                     {00000000 00000011 - mask all but cpl}
  59.                                   {ax = 00000000 000000?? now}
  60.   jnz   @lbl1
  61.   mov   @result, True             {privileged}
  62.   jmp   @exit
  63.  @lbl1:
  64.   mov   @result, False            {not privileged}
  65.  @exit:
  66.   pop   ax
  67. end;
  68.